package cn.fintecher.gis.web;


import cn.fintecher.gis.enums.FlowType;
import cn.fintecher.gis.enums.SusceptibleGrand;
import cn.fintecher.gis.model.request.StatisticalRequest;
import cn.fintecher.gis.model.response.LandStatisticalResponse;
import cn.fintecher.gis.model.response.PatrolStatisticalResponse;
import cn.fintecher.gis.model.response.ProjectResponse;
import cn.fintecher.gis.service.StatisticalItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/statistical")
@Api(value = "一张图相关功能管理", description = "一张图相关功能管理")
public class StatisticalController {

    @Autowired
    private StatisticalItemService statisticalItemService;


    @GetMapping("/queryStatisticalItem")
    @ApiOperation(value = "查询项目信息", notes = "查询项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<ProjectResponse>> queryFlowInfoFinish(Pageable pageable,
                                                                     @RequestParam(value = "flowType",required = false) FlowType flowType){
        List<ProjectResponse> list =  statisticalItemService.getProjectInfoByFlowType(flowType);
        Page<ProjectResponse> page = new PageImpl<>(list,pageable,list.size());
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/getStatisticalPatrolByType")
    @ApiOperation(value = "外业任务类型统计", notes = "外业任务类型统计")
    public ResponseEntity<List<PatrolStatisticalResponse>> getStatisticalPatrolByType(StatisticalRequest request){
        List<PatrolStatisticalResponse> list = statisticalItemService.getStatisticalPatrolByType(request);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getStatisticalPatrolByUser")
    @ApiOperation(value = "外业任务数量统计", notes = "外业任务数量统计")
    public ResponseEntity<List<PatrolStatisticalResponse>> getStatisticalPatrolByUser(StatisticalRequest request){
        List<PatrolStatisticalResponse> list = statisticalItemService.getStatisticalPatrolByUser(request);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getStatisticalDisasterByName")
    @ApiOperation(value = "外业地灾分布统计(根据名称)", notes = "外业地灾分布统计(根据名称)")
    public ResponseEntity<List<PatrolStatisticalResponse>> getStatisticalDisasterByName() throws Exception {
        List<PatrolStatisticalResponse> list = statisticalItemService.getStatisticalDisasterByName();
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getStatisticalDisasterByGrade")
    @ApiOperation(value = "外业地灾分布统计(根据级别)", notes = "外业地灾分布统计(根据级别)")
    public ResponseEntity<List<PatrolStatisticalResponse>> getStatisticalDisasterByGrade(@RequestParam("prefecture") String prefecture) throws Exception {
        List<PatrolStatisticalResponse> list = statisticalItemService.getStatisticalDisasterByGrade(prefecture);
        return ResponseEntity.ok().body(list);
    }


    @GetMapping("/getDisasterBySusceptible")
    @ApiOperation(value = "外业地灾分布统计(根据易发级别)", notes = "外业地灾分布统计(根据易发级别)")
    public ResponseEntity<List<PatrolStatisticalResponse>> getDisasterBySusceptible() throws Exception {
        List<PatrolStatisticalResponse> list = statisticalItemService.statSusceptible();
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/statSusceptibleAndGrad")
    @ApiOperation(value = "外业地灾分布统计(易发级别对应的危险统计)", notes = "外业地灾分布统计(易发级别对应的危险统计)")
    public ResponseEntity<List<PatrolStatisticalResponse>> statSusceptibleAndGrad(@RequestParam("susceptible") SusceptibleGrand susceptible) throws Exception {
        List<PatrolStatisticalResponse> list = statisticalItemService.statSusceptibleAndGrad(susceptible);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getLandStatisticalReport")
    @ApiOperation(value = "业务数据统计(报地)", notes = "业务数据统计(报地)")
    public ResponseEntity<List<LandStatisticalResponse>> getLandStatisticalReport(StatisticalRequest request) {
        List<LandStatisticalResponse> list = statisticalItemService.getLandStatisticalReport(request);
        return ResponseEntity.ok().body(list);
    }


    @GetMapping("/getLandStatisticalGrant")
    @ApiOperation(value = "业务数据统计(批地)", notes = "业务数据统计(批地)")
    public ResponseEntity<List<LandStatisticalResponse>> getLandStatisticalGrant(StatisticalRequest request) {
        List<LandStatisticalResponse> list = statisticalItemService.getLandStatisticalGrant(request);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getLandStatisticalExpropriation")
    @ApiOperation(value = "业务数据统计(征地)", notes = "业务数据统计(征地)")
    public ResponseEntity<List<LandStatisticalResponse>> getLandStatisticalExpropriation(StatisticalRequest request) {
        List<LandStatisticalResponse> list = statisticalItemService.getLandStatisticalExpropriation(request);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getLandStatistical")
    @ApiOperation(value = "业务数据统计(供地)", notes = "业务数据统计(供地)")
    public ResponseEntity<List<LandStatisticalResponse>> getLandStatistical(StatisticalRequest request) {
        List<LandStatisticalResponse> list = statisticalItemService.getLandStatisticalSupply(request);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getLandStatisticalRests")
    @ApiOperation(value = "业务数据统计(其他)", notes = "业务数据统计(其他)")
    public ResponseEntity<List<LandStatisticalResponse>> getLandStatisticalRests(StatisticalRequest request) {
        List<LandStatisticalResponse> list = statisticalItemService.getLandStatisticalRests(request);
        return ResponseEntity.ok().body(list);
    }
}
